package example.controller;


import example.service.login_check;
import example.service.user_c;
import org.json.JSONException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

@Controller
@Resource
public class zhuceContoller {

    @RequestMapping(value="/diqu_get",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public static String diqu_get() throws SQLException, JSONException {
        {
            return user_c.diqu_get();
        }
    }

    @RequestMapping(value="/yonghu_get",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public static String yonghu_get() throws SQLException, JSONException {
        {
            return user_c.yonghu_get();
        }
    }

    @RequestMapping(value="/user_change",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public static String user_change(HttpServletRequest req) throws SQLException, JSONException {
        {
            String username = req.getParameter("username");
            String oldpass = req.getParameter("oldpass");
            if (login_check.check(username , oldpass)){
                String password = req.getParameter("pass");
                String name = req.getParameter("name");
                String phone = req.getParameter("phone");
                user_c.change(username ,password , name , phone);
                return "1";
            }
            else {
                return "2";
            }
        }
    }

    @RequestMapping(value="/user_zhuce",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public static String user_zhuce(HttpServletRequest req) throws SQLException, JSONException {
        {
            String shengfen = req.getParameter("radio");
            String username = req.getParameter("username");
            String password = req.getParameter("pass");
            String name = req.getParameter("name");
            String phone = req.getParameter("phone");
            if ( shengfen.equals("1") ){
                String selfdiqu = req.getParameter("value");
                return user_c.selfzhuce(username , password , name , phone , selfdiqu);
            }
            else {
                String[] diqu = req.getParameterValues("checkList[]");
                return user_c.sellzhuce(username , password , name , phone , diqu);
            }

        }
    }

}
